package cn.yunhe.servlet;


import cn.yunhe.services.ShowFoodService;
import net.sf.json.JSONArray;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 周依博
 *
 * 菜品查询的servlet
 * 通过json遍历food表中的所有信息
 * 各个商家不同
 * @param
 * @return
 */
@WebServlet("/shangjia/ShowFoodServlet")
public class ShowFoodServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        int mid= (int) session.getAttribute("mid");
        ShowFoodService foodService = new ShowFoodService();
        JSONArray  jsonArray=  foodService.getAllFoodList(mid);
        out.print(jsonArray);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
